"use strict";

module.exports = function (sequelize, DataTypes) {
    var ChatMessage = sequelize.define("chatMessage", {
        targetType: {
            type: DataTypes.ENUM,
            values: ['single', 'group', 'unset'],
            defaultValue: 'unset',
        },
        type: {
            type: DataTypes.ENUM,
            values: ['text', 'image', 'audio', 'weblink', 'voice', 'unset'],
            defaultValue: 'unset',
        },
        text: {
            type: DataTypes.TEXT,
        },
        imageUri: {
            type: DataTypes.TEXT
        },
        audioUri: {
            type: DataTypes.TEXT
        },
        videoUri: {
            type: DataTypes.TEXT
        },
        weblink: {
            type: DataTypes.TEXT
        },
        toUserId: {
            type: DataTypes.INTEGER
        },
        sendTime: {
            type: DataTypes.INTEGER
        },
        msgid: {
            type: DataTypes.INTEGER,
            unique: true,
        },
        fromType: {
            type: DataTypes.TEXT,
        },
        voiceDuration: {
            type: DataTypes.TEXT,
        },
        media_crc32: {
            type: DataTypes.TEXT,
        },
        fsize: {
            type: DataTypes.INTEGER,
        }
    },
        {
            freezeTableName: true,
            paranoid: true,
            indexes: [
                {
                    unique: true,
                    fields: ['msgid']
                },
                {
                    unique: false,
                    fields: ['toUserId']
                },
                {
                    unique: false,
                    fields: ['targetType']
                }
            ],
        });

    ChatMessage.associate = function (models) {

    }

    return ChatMessage;
};